import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';

Vue.use(VueRouter);

const routes = [
  {
    path: '/home',
    name: 'home',
    component: Home,
    meta: {
      needLogin: true,
      menuName: '首页',
      isShow: true,
      icon: 'iconfont icon-index',
    },
    children: [

      {
        path: 'users',
        name: 'HomeUsers',
        component: () => import('../views/HomeUsers.vue'),
        meta: {
          needLogin: true,
          menuName: '用户管理',
          isShow: true,
          icon: 'iconfont icon-yonghuguanli',
        },
      },
      {
        path: 'personal',
        name: 'HomePersonal',
        component: () => import('../views/HomePersonal.vue'),
        meta: {
          needLogin: true,
          menuName: '个人中心',
          isShow: true,
          icon: 'iconfont icon-yonghuguanli',
        },
      },
      {
        path: 'classes',
        name: 'HomeClasses',
        component: () => import('../views/HomeClasses.vue'),
        meta: {
          needLogin: true,
          menuName: '班级管理',
          isShow: true,
          icon: 'iconfont icon-banjiguanli',
        },
      },
      {
        path: 'outlines',
        name: 'HomeOutlines',
        component: () => import('../views/HomeOutlines.vue'),
        meta: {
          needLogin: true,
          menuName: '大纲管理',
          isShow: true,
          icon: 'iconfont icon-dagangguanli',
        },
      },
      {
        path: 'items',
        name: 'HomeItems',
        component: () => import('../views/HomeItems.vue'),
        meta: {
          needLogin: true,
          menuName: '选项管理',
          isShow: true,
          icon: 'iconfont icon-xuanxiangguanli',
        },
      },
      {
        path: 'papers',
        name: 'HomePapers',
        component: () => import('../views/HomePapers.vue'),
        meta: {
          needLogin: true,
          menuName: '问卷管理',
          isShow: true,
          icon: 'iconfont icon-wenjuanguanli',
        },
      },
      {
        path: 'answers',
        name: 'HomeAnswers',
        component: () => import('../views/HomeAnswers.vue'),
        meta: {
          needLogin: true,
          menuName: '答卷管理',
          isShow: true,
          icon: 'iconfont icon-wenjuanguanli',
        },
      },

      {
        path: 'public/:id',
        name: 'HomePublish',
        component: () => import('../views/HomePublish.vue'),
        meta: {
          needLogin: true,
          menuName: '答卷',
          isShow: false,
          icon: 'iconfont icon-wenjuanguanli',
        },
        props: true,
      },
      {
        path: 'analysis',
        name: 'HomeAnalysis',
        component: () => import('../views/HomeAnalysis.vue'),
        meta: {
          needLogin: true,
          menuName: '分析',
          isShow: false,
          icon: 'iconfont icon-wenjuanguanli',
        },
        props: true,
      },
      {
        path: 'answerSheet',
        name: 'HomeAnswerSheet',
        component: () => import('../views/HomeAnswerSheet.vue'),
        meta: {
          needLogin: true,
          menuName: '答卷信息',
          isShow: false,
          icon: 'iconfont icon-wenjuanguanli',
        },
        props: true,
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue'),
    meta: {
      needLogin: false,
      menuName: '登录',
      isShow: false,
      icon: 'el-icon-s-opportunity',
    },
    beforeEnter: (to, from, next) => {
      if (!to.meta.needLogin) {
        if (localStorage.token) {
          next({ name: 'home' });
        }
      }
      next();
    },
  },
];

const router = new VueRouter({
  routes,
});

export default router;
